package com.ruoyi.project.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.project.domain.CxcyDemand;
import com.ruoyi.project.service.ICxcyDemandService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 企业需求Controller
 * 
 * @author yinhe
 * @date 2023-09-19
 */
@RestController
@RequestMapping("/demand")
public class CxcyDemandController extends BaseController
{
    @Autowired
    private ICxcyDemandService cxcyDemandService;

    /**
     * 查询企业需求列表
     */
    @RequiresPermissions("project:demand:list")
    @GetMapping("/list")
    public TableDataInfo list(CxcyDemand cxcyDemand)
    {
        startPage();
        List<CxcyDemand> list = cxcyDemandService.selectCxcyDemandList(cxcyDemand);
        return getDataTable(list);
    }

    /**
     * 导出企业需求列表
     */
    @RequiresPermissions("project:demand:export")
    @Log(title = "企业需求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CxcyDemand cxcyDemand)
    {
        List<CxcyDemand> list = cxcyDemandService.selectCxcyDemandList(cxcyDemand);
        ExcelUtil<CxcyDemand> util = new ExcelUtil<CxcyDemand>(CxcyDemand.class);
        util.exportExcel(response, list, "企业需求数据");
    }

    /**
     * 获取企业需求详细信息
     */
    @RequiresPermissions("project:demand:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cxcyDemandService.selectCxcyDemandById(id));
    }

    /**
     * 新增企业需求
     */
    @RequiresPermissions("project:demand:add")
    @Log(title = "企业需求", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CxcyDemand cxcyDemand)
    {
        return toAjax(cxcyDemandService.insertCxcyDemand(cxcyDemand));
    }

    /**
     * 修改企业需求
     */
    @RequiresPermissions("project:demand:edit")
    @Log(title = "企业需求", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CxcyDemand cxcyDemand)
    {
        return toAjax(cxcyDemandService.updateCxcyDemand(cxcyDemand));
    }

    /**
     * 删除企业需求
     */
    @RequiresPermissions("project:demand:remove")
    @Log(title = "企业需求", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cxcyDemandService.deleteCxcyDemandByIds(ids));
    }
}
